# -*- coding: utf-8 -*-

from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QApplication, QWidget,QMainWindow,QFileDialog
from PyQt5.QtGui import QIcon
import sys

PIANO_KEYBOARDS_POSITION = [8, 1400]
PIANO_KEYBOARD_WHITE_SIZE = [52.5, 400]
PIANO_KEYBOARD_BLACK_SIZE = [30, 200]

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.setWindowTitle("Piano Simulator")

        MainWindow.resize(3000, 2000)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")

        self.frame = QtWidgets.QFrame(self.centralwidget)
        self.frame.setGeometry(QtCore.QRect(0, 0, 3000, 2000))
        self.frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.frame.setFrameShadow(QtWidgets.QFrame.Raised)
        self.frame.setStyleSheet("background-color: rgb(0, 0, 0);")
        self.frame.setObjectName("frame")

        self.pianoKey = []
        for i in range(9):
            for j in range(7):
                if i * 7 + j < 5 or i * 7 + j > 56:
                    continue

                pBtn = QtWidgets.QPushButton(self.frame)
                pBtn.setGeometry(QtCore.QRect(PIANO_KEYBOARDS_POSITION[0] + PIANO_KEYBOARD_WHITE_SIZE[0] * (7 * i + j - 5), \
                    PIANO_KEYBOARDS_POSITION[1], PIANO_KEYBOARD_WHITE_SIZE[0], PIANO_KEYBOARD_WHITE_SIZE[1]))
                pBtn.setStyleSheet("background-color: rgb(255, 255, 255);")
                pBtn.setText("\n\n\n\n{}".format(j+1))
                pBtn.setObjectName("pianoKey{}".format(i * 12 + j))
                self.pianoKey.append(pBtn)

                # 中央C
                if i == 4 and j == 0:
                    pBtn.setStyleSheet("background-color: rgb(200, 200, 200);")
                    pBtn.setText("\n\n\n\n1")


                if i * 7 + j < 5 or i * 7 + j > 55:
                    continue

                if j  in [0,1,3,4,5]:
                    pBtn = QtWidgets.QPushButton(self.frame)
                    pBtn.setGeometry(QtCore.QRect(PIANO_KEYBOARDS_POSITION[0] + PIANO_KEYBOARD_WHITE_SIZE[0] * (7 * i + j - 5) +  PIANO_KEYBOARD_WHITE_SIZE[0] - PIANO_KEYBOARD_BLACK_SIZE[0] / 2,\
                        PIANO_KEYBOARDS_POSITION[1],\
                        PIANO_KEYBOARD_BLACK_SIZE[0], PIANO_KEYBOARD_BLACK_SIZE[1]))
                    pBtn.setStyleSheet("background-color: rgb(0, 0, 0);")
                    pBtn.setText("")
                    pBtn.setObjectName("pianoKey{}".format(i * 12 + j))
                    pBtn.raise_()
                    self.pianoKey.append(pBtn)

        for i in range(len(self.pianoKey)):
            if ((i + 9) % 12) in [1,3,6,8,10]:
                self.pianoKey[i].raise_()

        MainWindow.setCentralWidget(self.centralwidget)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
 
 
class myWindow(QMainWindow, Ui_MainWindow):
    def __init__(self):
        super().__init__()
        super().setupUi(self)
        
if __name__ == '__main__':
    #创建应用程序和对象
    app = QApplication(sys.argv)
    ex = myWindow()
    ex.show()
    sys.exit(app.exec_()) 